package com.lanou;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by admin on 19/1/18.
 */
@Controller
public class Hello {

    /**
     * @return
     * @Controller 和 @RequestMapping这两个注解
     * 相当于在jsp/servlet中@WebServlet的作用
     * 1.标识这个类是一个controller类（响应http请求的类）
     * 2.映射具体的url请求
     */
    @RequestMapping("/hello")
    public String hello(User user) {
        System.out.println(user);
        return "hello";
    }

    @RequestMapping("/world")
    public String world() {
        return "world";
    }


	/*@RequestMapping("/login")
    public String login(User user,HttpServletRequest request){
		String result = "error";
		if("zhangsan".equals(user.getUsername()) &&
				"123".equals(user.getPassword())) {
			result = "hello";
			request.setAttribute("username",user.getUsername());
		}
		return result;
	}*/

    @RequestMapping("/login")
    public ModelAndView login(User user) {
        ModelAndView modelAndView = new ModelAndView();


        modelAndView.setViewName("login");


        return modelAndView;
    }


    @RequestMapping("/success/chinese")
    public String chinese()  {

		/*byte[] b = username.getBytes("iso-8859-1");
		String utf8Username = new String(b,"utf-8");
		System.out.println(utf8Username);*/
        return "lol";
    }
}
